<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/jsp/common/headMain.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
  <head>
	<title>申请用户列表</title>
  </head>

	<script type="text/javascript">
		function _addapplyUser() {
			_reloadForm();
			$("#_addDIV").dialog({
				height:400,width:500,resizable:false,modal:true, //这里就是控制弹出为模态                
				buttons: {
					"确定":function() {
						$.post("${base}/applyUser_addapplyUser", 
							$('#_addForm').serialize(), 
							function(response) {
								if (response && response.success) {
									alert(response.msg);
									$("#_applyUserGrid").jqGrid('setGridParam',{url: '${base}/applyUser_getList/${shopid}'}).trigger("reloadGrid");
								} else {
									alert(response.msg);
								}
						}, "json");
						$(this).dialog("close");
					},                    
					"取消":function() {
						$(this).dialog("close");
					}                
				}            
			});
		}
		
		function _delapplyUser(id) {
			if (confirm("删除商家吗？")) {
				$.post("${base}/applyUser_deleteapplyUser/" + id, 
					function(data) {
						if (data && data.success) {
							alert(data.msg);
							$("#_applyUserGrid").jqGrid('setGridParam',{url: '${base}/applyUser_getList/${shopid}'}).trigger("reloadGrid");
						} else {
							alert(data.msg);
						}
					}, 
				"json");
			}
		}
		
		function _updateapplyUser(id) { 
  			//单击修改链接的操作
  			var model = $("#_applyUserGrid").jqGrid('getRowData', id);
			$("#m_name").val(model.name);
			$("#m_price").val(model.price);
			$("#m_applyUserunit").val(model.applyUserunit);
			$("#m_shopid").val(model.shopid);
			$("#m_sequence").val(model.sequence);
			$("input[name='status'][value='" + model.status + "']").attr("checked", true);
			$("#_updateDIV").dialog({
				height:400,width:500,resizable:false,modal:true, //这里就是控制弹出为模态                
				buttons: {
					"确定":function() {
						$.post("${base}/applyUser_updateapplyUser/" + id, 
							$('#_updateForm').serialize(), 
							function(response) {
								if (response && response.success) {
									alert(response.msg);
									$("#_applyUserGrid").jqGrid('setGridParam',{url: '${base}/applyUser_getList/${shopid}'}).trigger("reloadGrid");
								} else {
									alert(response.msg);
								}
						}, "json");
						$(this).dialog("close");
					},                    
					"取消":function() {
						$(this).dialog("close");
					}                
				}            
			});
		}
		alert("${shopId}");
		$(function(){
				jQuery("#_applyUserGrid").jqGrid({
				   	url: "${base}/shop_getApplyUserList/${shopId}",
					datatype: "json",
				   	colNames:['ID','用户ID','店铺ID','状态'],
				   	colModel:[
				   		{name:'ID',index:'ID', align:'center',hidden:true},
				   		{name:'USID',index:'USID', align:'center',hidden:true},
				   		{name:'SHOPID', index:'SHOPID', align:'center'},
				   		{name:'STATUS', index:'STATUS', align:'center'},
				   	],
				   	width:900,
				   	height:230,
				   	rowNum:10,
				   	rowList:[10,20,30],
				   	pager: '#applyUserBar',
				   	sortname: 'id',
				    viewrecords: true,
				    sortorder: "desc",
					multiselect: false,
					jsonReader: {
						repeatitems : false
					},
					rownumbers : true,
					caption: "申请用户列表",
					afterInsertRow : function(rowid, data) {
						$("#_applyUserGrid").jqGrid('setCell', rowid, 'ctrl', '<span style="cursor:pointer;" onclick="_updateapplyUser(' + data.id + ');">修改</span>|<span style="cursor:pointer;" onclick="_delapplyUser(' + data.id + ');">删除</span>', {color:'green'});
					}
				});
				jQuery("#_applyUserGrid").jqGrid('navGrid','#applyUserBar',{add : false, del : false, edit : false, refresh : true, search : false});
				
		});
		
		function _reloadForm() {
			$("#_addDIV").children(":input[type='text']").each(function(){
				$(this).val("");
			});
		}
		
		function _back() {
			window.location.href = '${base }/shop_shopManagerList';
		}
		</script>
	<body>
	<div class="subScroll tree_subScroll" id="subScroll"><!-- 滚动条 -->
	<table cellpadding="0" cellspacing="0" border="0" width="99%" style="height:100%;">
		<tr><td style="height:10px; overflow:hidden;" colspan="2"></td></tr>
		<tr>
			<!--右边内容-->
			<td width="*" valign="top" class="contList">
				<div id="applyUserManagerDiv">
					<!-- 显示食物列表 --> 
					<table id="_applyUserGrid"></table>
					<div id="applyUserBar"></div>
					<div class="contBtn" style="width:900px; _width:902px;">
						<input type="button" value="增加食物" class="btn" onclick="_addapplyUser();" />
						<input type="button" value="返回" class="btn" onclick="_back();" />
					</div>
					<div id="_addDIV" title="增加食物" style="display:none;">
						<form id="_addForm" style="margin-top: 20px;padding:2px;">
							<input type="hidden" id="a_shopid" name="shopid" value="${shopid }" />
							<p>食物名称：<input type="text" id="a_name" name="name" /></p>
							<p>价格：<input type="text" id="a_price" name="price" /></p>
							<p>单位：<input type="text" id="a_applyUserunit" name="applyUserunit" /></p>
						</form>
					</div>
					<div id="_updateDIV" title="修改食物" style="display:none;">
						<form id="_updateForm" style="margin-top: 20px;padding:2px;">
							<input type="hidden" id="m_shopid" name="shopid" value="${shopid }" />
							<input type="hidden" id="m_sequence" name="sequence" />
							<p>食物名称：<input type="text" id="m_name" name="name" /></p>
							<p>价格：<input type="text" id="m_price" name="price" /></p>
							<p>单位：<input type="text" id="m_applyUserunit" name="applyUserunit" /></p>
							<p>状态：
								<input type="radio" name="status" value="0" />未发布
								<input type="radio" name="status" value="1" />已发布
								<input type="radio" name="status" value="2" />下架									
							</p>
						</form>
					</div>
				</div>
			</td>
	</table>
	</div>
	</body>
</html>